#include  <msp430x54xA.h>


#define Max_Pack_Data_Size     2

///////////////////////////////////////////////////////////////
// Pack Command define
#define  _SerialNumber_                  0x1c     //--> "serialNumber" command has to put first item.
#define  _AtRate_                        0x04     //
#define  _Temperature_                   0x08     //
#define  _Voltage_                       0x09     //
#define  _Current_                       0x0a     //positive for charge, negative for discharge.
#define  _AverageCurrent_                0x0b     //
#define  _RelativeStateOfCharge_         0x0d     //
#define  _RemainingCapacity_             0x0f     //
#define  _FullChargeCapacity_            0x10     //
#define  _BatteryStatus_                 0x16     //
#define  _CycleCount_                    0x17     //
#define  _CellVoltage4_                  0x3c     //
#define  _CellVoltage3_                  0x3d     //
#define  _CellVoltage2_                  0x3e     //
#define  _CellVoltage1_                  0x3f     //

// Extended SBS Command after 0x45
#define  _ManufacturerAccess_            0x00     //
#define  _FETControl_                    0x46     //
#define  _OperationStatus_               0x54     //
#define  _LastOfCmdIndex_                0xff     // the element has to be put last

enum PackCommandIndex{
  serialNumber,
  //atRate,
  temperature,
  voltage,
  current,  //positive for charge, negative for discharge.
  //averageCurrent,
  relativeStateOfCharge,
  remainingCapacity,
  fullChargeCapacity,
  batteryStatus,
  cycleCount,
  cellVoltage4,
  cellVoltage3,
  cellVoltage2,
  cellVoltage1,
  /////////////////////////////////////////////////////////////////////////
  // if it is Extended SBS Command, please put it after ManufacturerAccess
  ManufacturerAccess,
  //FETControl,
  //OperationStatus,
  lastOfCmdIndex         //the element has to be put last
};

//const unsigned char PackCommand[] = 
//{
//  _SerialNumber_                  ,    //--> "serialNumber" command has to put first item.
//  //_AtRate_                        ,    //
//  _Temperature_                   ,    //
//  _Voltage_                       ,    //
//  _Current_                       ,    //positive for charge, negative for discharge.
//  //_AverageCurrent_                ,    //
//  _RelativeStateOfCharge_         ,    //
//  _RemainingCapacity_             ,    //
//  _FullChargeCapacity_            ,    //
//  _BatteryStatus_                 ,    //
//  _CycleCount_                    ,    //
//  _CellVoltage4_                  ,    //
//  _CellVoltage3_                  ,    //
//  _CellVoltage2_                  ,    //
//  _CellVoltage1_                  ,    //
//  /////////////////////////////////////////////////////////////////////////
//  // if it is Extended SBS Command, please put it after ManufacturerAccess
//  _ManufacturerAccess_            ,
//  //_FETControl_                    ,
//  //_OperationStatus_               ,
//  _LastOfCmdIndex_                     // the element has to be put last
//};


////////////////////////////////////
// For ManufacturerAccess
#define SealedSecurityMode        BIT5
#define ManufacturerAccessCmd     0x00
#define UnSealedWord1             0x0414
#define UnSealedWord2             0x3672

///////////////////////////////////
// For _FETControl_ bit
//Low Byte
#define PackFETDSGBit       BIT1
#define PackFETCHGBit       BIT2
//High Byte


///////////////////////////////////
// For _BatteryStatus_ bit
//Low Byte
#define Pack_LB_EC0_Bit       BIT0    //Error Code, returns status of processed SBS function
#define Pack_LB_EC1_Bit       BIT1    //Error Code, returns status of processed SBS function
#define Pack_LB_EC2_Bit       BIT2    //Error Code, returns status of processed SBS function
#define Pack_LB_EC3_Bit       BIT3    //Error Code, returns status of processed SBS function
#define Pack_LB_FD_Bit        BIT4    //Fully Discharged
#define Pack_LB_FC_Bit        BIT5    //Fully Charged
#define Pack_LB_DSG_Bit       BIT6    //Discharging
#define Pack_LB_INIT_Bit      BIT7    //1 = Initialization. This flag is cleared approximately 1 second after device reset

//High Byte
#define Pack_HB_RTA_Bit       BIT0    //Remaining Time Alarm
#define Pack_HB_RCA_Bit       BIT1    //Remaining Capacity Alarm
#define Pack_HB_RSVD_Bit      BIT2
#define Pack_HB_TDA_Bit       BIT3    //Terminate Discharge Alarm
#define Pack_HB_OTA_Bit       BIT4    //Over Temperature Alarm
//#define Pack_HB_RSVD_Bit      BIT5
#define Pack_HB_TCA_Bit       BIT6    //Terminate Charge Alarm
#define Pack_HB_OCA_Bit       BIT7    //Over Charged Alarm

